
<template>
	<el-dialog title="" visible :show-close="false" :modal-append-to-body="false" class="wrap" size="tiny">
		 <div class="bt">退费</div>
		<i class="el-icon-close close" @click="cancel" style="color: white;"></i>
		<el-form label-width="100px" class="form">
			<el-form-item label="学生名称">
				  <el-input v-model="form.zwm"  icon="info" class="select-block"></el-input>
			</el-form-item>
            <el-form-item label="余额(可退)">
                <el-input v-model="form.yuer" :readonly="true" class="select-block"></el-input>
            </el-form-item>
            <el-form-item label="未上课时">
                <el-input v-model="params.row.syks"  class="select-block"></el-input>
            </el-form-item>
			<el-form-item label="退费金额">
				  <el-input v-model="tfje"  class="select-block"></el-input>
			</el-form-item>
			<el-form-item label="退费原因">
				 <!-- <el-input v-model="form.ms" :readonly="true" icon="info" class="select-block"></el-input>-->
				  <el-input v-model="form.tfyy" type="textarea"  :rows="4"   icon="info" class="select-block" ></el-input>
			</el-form-item>

		</el-form>
		<el-button type="primary" class="submit" @click="loadinfo">确定</el-button>
	</el-dialog>
</template>

<script type="text/javascript">
	import qs from 'qs'
	export default {
		props: ['params'],
		data() {
			return {
				form: {
					zwm:'',
					syks:'',
					tfyy:'',
					yuer:'',
					id:''
				},
					tfje:'',
			}
		},
		created() {
		   console.log(this.params.row)
           this.form.zwm=this.params.row.zwm;
           this.form.id=this.params.row.id;
           this.form.xsid=this.params.row.xsid;
           this.form.yuer=this.params.row.tfje;


		},
		 watch:{
            'tfje': function(newVal,oldVal){
                if(parseInt(newVal) > parseInt(this.form.yuer)) {//如果小于等于零
//                  this.tfje = this.form.yuer//恢复原值
					this.tfje = 0
                     this.$message.warning('输入余额超过可退余额!')
                }
            }
        },
		methods: {
			loadinfo(){
				 var logininfo = JSON.parse(localStorage.logininfo) ;
				 var params3 = qs.stringify({
							 xxid:logininfo.xxid,
							 xsid:this.form.xsid,
							 tfje:this.tfje,
							 tfyy:this.form.tfyy,
							 xsksid:this.form.id
						});
				 this.axios.post(this.$store.state.api+'xstf/add',params3)
				 .then( res =>  {
						if(res.data.code == 1) {
							this.$emit('close', { type: 'info', cancel: false });
							this.$store.state.loading = false;
						} else {
							this.$emit('close', { type: 'info', cancel: false });
							this.$store.state.loading = false;
						}
					 }).catch(res => {
						 this.$message.warning("服务器异常");
			 				this.$emit('close', { type: 'info', cancel: true });
			 				this.$store.state.loading = false;
					 })
			},
			cancel() {
				this.$emit('close', { type: 'info', cancel: true })
			},
			},
			computed: {
//       	tfje(){
//          let number = this.params.row.syks * this.params.row.jcjg;
//          if (number<=0) {
//            return 0.00
//          }
//          return number
//        },
//        tfje(){
//          let number = this.form.syks * this.params.row.jcjg;
//          if (number<=0) {
//            return 0.00
//          }else if(number<=this.params.row.tfje){
//          	return number
//          }else{
//          	this.$message.warning('输入课时有误')
//          }
//        },
         }

	}
</script>

<style lang="less" scoped>
	.wrap {
		text-align: center;
	}
	.bt{
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top:0;
			left:0;
			background: #50BFFF;
			margin-bottom: 20px;
			color:white;
			text-align:left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
	.form {
		text-align: left;
		margin-top: 15px;
	}
	.select-block {
		display: block;
	}

	.submit {
		width: 120px;
	}
</style>
